package sk.datalan.similarity;

import org.openrdf.model.Value;
import org.openrdf.model.ValueFactory;
import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
import org.openrdf.query.algebra.evaluation.function.Function;

import sk.datalan.similarity.predicates.Image;

/*
 * Testovacia class, ale performance takejto triedy je velmi ubohy v porovnani s java mapperom.
 */
public final class SimilarityFunc implements Function {

	
	
	public static final String NAMESPACE = "http://www.datalan.sk/semweb/function/";

	@Override
	public Value evaluate( ValueFactory valueFactory, Value... args ) throws ValueExprEvaluationException {
		// our palindrome function expects only a single argument, so throw an
		// error
		// if there's more than one
		if ( args.length != 3 ) {
			throw new ValueExprEvaluationException( "SparqlComparison function requires" + "exactly 3 arguments, got " + args.length );
		}
		double similarity = 0;
		String predicate = args[0].stringValue();

		if ( "http://www.datalan.sk/semweb/ontology/realestate/1.0/realestate.owl#area".equals( predicate ) ) {
			similarity = Integer.parseInt( args[1].stringValue() ) / Integer.parseInt( args[2].stringValue() );
		} else if ( "http://www.datalan.sk/semweb/ontology/realestate/1.0/realestate.owl#imageHash".equals( predicate ) ) {
			similarity = Image.calculateDistance( args[1].stringValue(), args[2].stringValue() );
		} else if ( "http://www.datalan.sk/semweb/ontology/realestate/1.0/realestate.owl#objectStatus".equals( predicate ) ) {

		} else {
		}
		return valueFactory.createLiteral( similarity );
	}

	@Override
	public String getURI() {
		return NAMESPACE + "compare";
	}

}
